package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.atguigu.jxc.util.R;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @PostMapping("/list")
    public R list(Integer page, Integer rows, String supplierName){
        Page<Supplier> suppliers = supplierService.page(page,rows,supplierName);
        System.out.println(suppliers);
        return R.ok().put("rows",suppliers);
    }

    @PostMapping("/save")
    public ServiceVO save(Supplier supplier,Integer supplierId){
        System.out.println(supplierId);
        System.out.println(supplier);

        if (supplierId == null){
            supplierService.save(supplier);
            return new ServiceVO(100,"添加成功");
        }else{
            supplierService.update(supplier,supplierId);
            return new ServiceVO(100,"修改成功");
        }


    }

    @PostMapping("/delete")
    public ServiceVO delete(@RequestParam("ids") String ids){
        supplierService.delete(ids);
        return new ServiceVO(100,"删除成功");
    }

}
